package com.eqdd.yiqidian.ui.share;

import android.content.Intent;
import android.content.res.Configuration;
import android.databinding.DataBindingUtil;

import com.eqdd.yiqidian.R;
import com.eqdd.yiqidian.base.BaseActivity;
import com.eqdd.yiqidian.VideoPlayActivityCustom;
import com.eqdd.yiqidian.base.Config;
import com.eqdd.yiqidian.utils.FileProviderUtil;

import android.net.Uri;
import android.os.Environment;
import android.os.ParcelFileDescriptor;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.FileProvider;
import android.text.TextUtils;
import android.view.View;

import java.io.File;

import chuangyuan.ycj.videolibrary.video.ManualPlayer;

public class VideoPlayActivity extends BaseActivity {
    private VideoPlayActivityCustom dataBinding;
    private String url;
    private ManualPlayer exoPlayerManager;

    @Override
    public void initBinding() {
        dataBinding = DataBindingUtil.setContentView(this, R.layout.activity_video_play);
        initTopTitleBar(View.VISIBLE, "标题");
    }

    @Override
    public void initData() {
        Intent intent = getIntent();
        exoPlayerManager = new ManualPlayer(this, R.id.exo_play_context_id);
        exoPlayerManager.setTitle("视频标题");
        url = intent.getStringExtra(Config.VIDEO_URL);
        if (TextUtils.isEmpty(url)) {
            Uri data = intent.getData();
            if (data != null) {
//                url = data.getPath();
//
//                url = Environment.getExternalStorageDirectory() + url.substring(14, url.length());
                exoPlayerManager.setPlayUri(data);

            }
        } else {
            //实例化播放控制类

            //自定义你的数据源，后面详细介绍如何自定义数据源类
            // ManualPlayer exoPlayerManager = new ManualPlayer(this,R.id.exo_play_context_id,new DataSource(this));
            //加载m3u8
//        exoPlayerManager.setPlayUri("http://dlhls.cdn.zhanqi.tv/zqlive/35180_KUDhx.m3u8");
            //加载ts.文件
//        exoPlayerManager.setPlayUri("http://185.73.239.15:25461/live/1/1/924.ts");
            //播放本地视频
            System.out.println("播放视频地址:" + url);
            exoPlayerManager.setPlayUri(url);
            //下面开启多线路播放
//        exoPlayerManager.setShowVideoSwitch(true); //开启切换按钮，默认关闭
//        String[] test = {"http://120.25.246.21/vrMobile/travelVideo/zhejiang_xuanchuanpian.mp4", "http://120.25.246.21/vrMobile/travelVideo/zhejiang_xuanchuanpian.mp4", "http://120.25.246.21/vrMobile/travelVideo/zhejiang_xuanchuanpian.mp4"};
//        String[] name = {"超清", "高清", "标清"};
//        exoPlayerManager.setPlaySwitchUri(test, name);
            //添加水印图片
            // exoPlayerManager.setExoPlayWatermarkImg();
        }

    }

    @Override
    public void setView() {

    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {

        }
    }

    @Override
    public void onResume() {
        super.onResume();
        exoPlayerManager.onResume();
    }

    @Override
    public void onPause() {
        super.onPause();
        exoPlayerManager.onPause();
    }


    @Override
    protected void onDestroy() {
        exoPlayerManager.onDestroy();
        super.onDestroy();

    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        exoPlayerManager.onConfigurationChanged(newConfig);//横竖屏切换
        super.onConfigurationChanged(newConfig);
    }

    @Override
    public void onBackPressed() {
        //使用播放返回键监听
        if (exoPlayerManager.onBackPressed()) {
            ActivityCompat.finishAfterTransition(this);
        }
    }
}
